<template>
  <div class="edit">
    <el-form :model="addForm" label-width="120px">
      <el-form-item label="停车场:"> {{addForm.parkName}} </el-form-item>
      <el-form-item label="会员卡类型:">{{addForm.uniformRentType | uniformRentTypeFilter}}</el-form-item>
      <el-form-item label="车场端展示状态:">
        <el-radio v-model="addForm.ownerStatus" label="1">开启</el-radio>
        <el-radio v-model="addForm.ownerStatus" label="0">关闭</el-radio>
      </el-form-item>
      <el-form-item label="车主端展示状态:">
        <el-radio v-model="addForm.clientStatus" label="1">开启</el-radio>
        <el-radio v-model="addForm.clientStatus" label="0">关闭</el-radio>
      </el-form-item>
      <el-form-item label="车场售价:">
        <el-input maxlength="5" v-model.number="addForm.parkAmount" size="mini" style="width: 120px;">
          <template slot="append">元</template>
        </el-input>
      </el-form-item>
      <el-form-item label="平台售价:">
        <el-input maxlength="5" v-model.number="addForm.amount" size="mini" style="width: 120px;">
          <template slot="append">元</template>
        </el-input>
      </el-form-item>
      <el-form-item label="起止时间:" v-if="addForm.uniformRentType >= 100">
        <el-time-picker
            is-range
            v-model="dateTime"
            format="HH:mm"
            value-format="HH:mm"
            @change="changeTime"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            placeholder="选择时间范围">
          </el-time-picker>
      </el-form-item>
    </el-form>
    <p style="text-align: center;">
      <el-button size="mini" type="primary" @click="confirm">确定</el-button>
    </p>
  </div>
</template>

<script>
  export default {
    props: ['row'],
    filters: {
      uniformRentTypeFilter(type) {
        switch(type) {
          case 1:
            return '全天年卡';
          case 2:
            return '全天季卡';
          case 4:
            return '全天月卡';
          case 100:
            return '白天月卡';
          case 110:
            return '夜间月卡';
        }
      }
    },
    data() {
      return {
        addForm: {},
        dateTime: []
      }
    },
    mounted() {
      this.row.ownerStatus = this.row.ownerStatus == false ? '0' : this.row.ownerStatus;
      this.row.clientStatus = this.row.clientStatus == false ? '0' : this.row.clientStatus;
      this.row.ownerStatus = this.row.ownerStatus == 1 ? '1' : this.row.ownerStatus;
      this.row.clientStatus = this.row.clientStatus == 1 ? '1' : this.row.clientStatus;
      this.addForm = this.row;
      this.dateTime = [this.row.beginTime,this.row.endTime]
    },
    methods: {
      changeTime(v) {
        this.addForm.beginTime = v[0];
        this.addForm.endTime = v[1];
      },

      confirm() {
        this.$axios({
          method: 'post',
          url: '/promotion/month-rule/update-month-rule',
          data: this.addForm
        }).then((res) => {
          if(res.code == 200) {
            this.$message.success('编辑规则成功');
            this.$emit('closeDialog');
          } else {
            this.$message.warning('编辑规则失败');
          }
        })
      }
    }
  }
</script>

<style scoped>
  .el-form-item {
    display: inline-block;
    width: 350px;
  }




</style>
